package com.txl.domain;

import java.util.HashMap;
import java.util.Map;

import com.txl.utils.ServiceUtils;

public class PasswordForm {

	private String password;//原来的密码
	private String password1;//新密码
	private String password2;//确认密码
	private Map errors = new HashMap();

	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getPassword1() {
		return password1;
	}
	public void setPassword1(String password1) {
		this.password1 = password1;
	}
	public String getPassword2() {
		return password2;
	}
	public void setPassword2(String password2) {
		this.password2 = password2;
	}
	
	public Map getErrors() {
		return errors;
	}
	public void setErrors(Map errors) {
		this.errors = errors;
	}
	//校验数据的合法性，传入旧密码
	public boolean volidate(UserBean user){
		boolean isOK = true;
		
		if(!ServiceUtils.md5(this.password).equals(user.getPassword())){
			errors.put("password", "密码输入有误");
			isOK = false;
		}
		
		if(password1==null || password1.trim().equals("")){
			errors.put("password1", "密码不能为空");
			isOK = false;
		}else if(!password1.matches("\\d{6,8}")){
			errors.put("password1", "密码6-8位");
			isOK = false;
		}
		
		if(password2==null || password2.trim().equals("")){
			errors.put("password2", "密码不能为空");
			isOK = false;
		}else if(!password2.equals(password1)){
			errors.put("password2", "两次输入的密码不一样");
			isOK = false;
		}
		
		return isOK;
		
	}
}
